//------------------------------------------------------------------------------
// <copyright file="IListExtension.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace DAnton.Utilities.Extensions
{
    public static class IListExtension
    {
        public static void AddRange<T>(this IList<T> list, IEnumerable<T> items)
        {
            if (items == null)
                throw new ArgumentException("Items collection cannot be null");

            foreach (var item in items)
                list.Add(item);
        }

        public static void AddRange(this IList list, IEnumerable items)
        {
            if (items == null)
                throw new ArgumentException("Items collection cannot be null");

            foreach (var item in items)
                list.Add(item);
        }

        public static IList<T> Clone<T>(this IList<T> list) where T : ICloneable
        {
            return list.Select(item => (T)item.Clone()).ToList();
        }
    }
}
